﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
/// <summary>
///Class1 的摘要说明
/// </summary>
public class InterfaceManager
{
    
    public const int ItemNumOfOnePage = 5;
    public static IDataInterface DataManager = new DataImplement();
    public static void RegisterDataInterface(IDataInterface i)
    {
        DataManager = i;
    }

    public class DefaultDataInterface : IDataInterface
    {
        #region 查看商品
        /// <summary>
        /// 获得在第currentPage页上将要显示的商品
        /// currentPage从0开始计算，每页包括ItemNumOfOnePage个商品
        /// 只显示部分商品信息包括(........................................)
        /// </summary>
        /// <param name="category">商品的类别</param>
        /// <param name="ItemNumOfOnePage">一个页面显示的商品个数</param>
        /// <param name="currentPage">当前在第几页，从0开始计算</param>
        /// <returns>一个商品对象列表</returns>
        public List<Item> GetItemList(ItemCategory category, int ItemNumOfOnePage, int currentPage)
        {
            List<Item> items = new List<Item>();
            Item item = new Item();
            for (int i = 0; i < ItemNumOfOnePage; i++)
            {
                item.id = i;
                item.picAddress = "~/images/Logo.png";
                item.currentPrice = 12;
                item.reservePrice = 11;
                item.description = "very good";
                items.Add(item);
            }

            return items;
        }

        /// <summary>
        /// 根据关键字进行商品搜索
        /// </summary>
        /// <param name="key">key words</param>
        /// <param name="ItemNumOfOnePage">一个页面显示的商品个数</param>
        /// <param name="currentPage">当前在第几页，从0开始计算</param>
        /// <returns>一个商品对象列表</returns>
        public List<Item> GetItemListKeyWord(string key, int ItemNumOfOnePage, int currentPage)
        {

            List<Item> items = new List<Item>();
            Item item = new Item();
            for (int i = 0; i < ItemNumOfOnePage; i++)
            {
                item.id = i;
                item.picAddress = "~/images/Logo.png";
                item.currentPrice = 3312;
                item.reservePrice = 33311;
                item.description = "key + search";
                items.Add(item);
            }
            return items;
        }


        /// <summary>
        /// 获得编号为itemId的商品详细信息
        /// 详细信息包括(.................................)
        /// </summary>
        /// <param name="itemId">商品编号</param>
        /// <returns>一个商品对象</returns>
        public Item GetItem(int itemId)
        {
            Item item = new Item();
            User auctioneer = new User();
            List<Bid> bis = new List<Bid>();
            User usr = new User();
            usr.userName = "seven";
            Bid bid = new Bid();
            bid.datetime = DateTime.Now;
            bid.user = usr;
            bid.price = 123;
            bid.itemId = itemId;

            for (int i = 0; i < 6; i++)
            {
                bis.Add(bid);
            }

            auctioneer.userName = "eleven";
            item.id = itemId;
            item.picAddress = "~/images/Logo.png";
            item.goodName = "Dell Laptop";
            item.auctioneer = auctioneer;
            item.currency = Currency.RMB;
            item.condition = Condition.BAD;
            item.bids = bis;
            item.currentPrice = 12;
            item.description = "very good";
            item.payMethod = PayMethod.VISA;

            return item;
        }
        #endregion

        #region  目录信息
        /// <summary>
        /// 获取所有的目录
        /// </summary>
        /// <returns>所有的目录的list</returns>
        public List<ItemCategory> GetAllItemCategory()
        {
            List<ItemCategory> cates = new List<ItemCategory>();
            ItemCategory cate = new ItemCategory();
            for (int i = 0; i < 4; i++)
            {
                cate.category = "apple";
                cates.Add(cate);
            }
            return cates;
        }
        #endregion

        #region  用户信息
        /// <summary>
        /// 获取当前登录的用户的基本信息
        /// 基本信息包括
        /// </summary>
        /// <param name="usrId">用户Id</param>
        /// <returns>用户对象</returns>
        public User GetUsrBasicInfo(int usrId)
        {
            return null;
        }

        /// <summary>
        /// 获取用户的WatchList
        /// 信息包括：note,Item信息()
        /// </summary>
        /// <param name="usrId">用户Id</param>
        /// <returns>用户Watch信息列表</returns>
        public List<Watch> GetAllWatchs(int usrId)
        {
            List<Watch> items = new List<Watch>();
            
            for (int i = 0; i < ItemNumOfOnePage; i++)
            {
                Watch item = new Watch();
                //item.item = new Item();
                //item.user = new User();
                //item.note = "1111111111";
                //item.user.userId = usrId;
                //item.item.id = i;
                //item.item.picAddress = "~/images/Logo.png";
                //item.item.currentPrice = 12;
                //item.item.reservePrice = 11;
                //item.item.description = "very good";
                //item.item.goodName = i.ToString();
                //item.item.closingDatetime = DateTime.Now;
                items.Add(item);
            }

            return items;
        }

        /// <summary>
        /// 获取用户所有的Bid信息(作为买家)
        /// 信息包括:datetime, datetime, Item(),isVectory
        /// </summary>
        /// <param name="usrId"></param>
        /// <returns></returns>
        public List<Bid> GetAllBids(int usrId)
        {
            List<Bid> items = new List<Bid>();
            for (int i = 0; i < ItemNumOfOnePage; i++)
            {
                Bid item = new Bid();
                item.datetime = DateTime.Now;
                item.price = 123123;
                //item.item = new Item();
                //item.user = new User();
                //item.user.userId = 0;
                //item.item.id = i;
                //item.item.picAddress = "~/images/Logo.png";
                //item.item.currentPrice = 12;
                //item.item.reservePrice = 11;
                //item.item.goodName = i.ToString();
                //item.item.description = "very good";
                //item.item.closingDatetime = DateTime.Now;
                items.Add(item);
            }
            return items;
        }

        #endregion

        #region  feedback
        /// <summary>
        /// 获得用户的所有feedback信息，所有信息包括reply
        /// </summary>
        /// <param name="usrId">用户id</param>
        /// <returns>feebback列表</returns>
        public List<Feedback> GetAllFeedback(int usrId)
        {
            return null;
        }


        /// <summary>
        /// 添加评论
        /// </summary>
        /// <param name="bidderId">买家id</param>
        /// <param name="auctioneerId">买家id</param>
        /// <returns>是否添加成功</returns>
        public bool AddFeedback(Feedback fb)////更改
        {
            return true;
        }


        /// <summary>
        /// 添加对某个feedback的回复
        /// </summary>
        /// <param name="feedbackid">feedback id</param>
        /// <returns>是否添加成功</returns>
        public bool AddReply(Feedback fb)
        {
            return true;
        }
        #endregion

        #region  投标
        /// <summary>
        /// 买家对一个商品成功投标，添加这个投标
        /// </summary>
        /// <param name="usrId">买家id</param>
        /// <param name="ItemId">商品id</param>
        /// <returns>是否添加投标成功</returns>
        public bool AddBid(int usrId, int ItemId, double price, DateTime time)
        {
            return true;
        }

        /// <summary>
        /// 修改一个bid的信息
        /// </summary>
        /// <param name="bidId">bidId</param>
        /// <param name="itemId">itemId</param>
        /// <param name="state">状态</param>
        public void setBidState(int bidId, int itemId, int state)
        {
            return;
        }

        #endregion

        #region  关注商品
        /// <summary>
        /// 买家关注一个商品，添加这个Watch
        /// </summary>
        /// <param name="usrId">买家id</param>
        /// <param name="ItemId">商品id</param>
        /// <returns>是否添加Watch成功</returns>
        public bool AddWatch(int usrId, int ItemId)
        {
            return true;
        }
        #endregion

        #region  拍卖
        /// <summary>
        /// 拍卖时间截止，更新商品信息
        /// </summary>
        /// <param name="itemId">商品id</param>
        /// <returns>是否更新成功</returns>
        public bool SellOutItem(int itemId)
        {
            return true;
        }

        ///// <summary>
        ///// 获得胜出的买家的信息
        ///// </summary>
        ///// <param name="itemId">商品id</param>
        ///// <returns>买到这个商品的用户对象</returns>
        //public User GetVectoryBidder(int itemId)
        //{
        //    return null;
        //}
        #endregion

        #region  登陆注册
        /// <summary>
        /// 用户信息是否匹配成功，用户ID和密码
        /// </summary>
        /// <param name="Id">用户ID</param>
        /// <param name="ps">用户密码</param>
        /// <returns>是否登陆成功</returns>
        public int Login(string username, string ps)//??????????????????????????????Id or Name
        {
            return -1;
        }

        /// <summary>
        /// 用户注册是否成功
        /// </summary>
        /// <param name="Id">用户名</param>
        /// <param name="ps">密码</param>
        /// <param name="email">email地址</param>
        /// <returns>是否注册成功</returns>
        public int Register(string name, string ps, string email)
        {
            return 0;
        }
        #endregion


        public Feedback GetFeedbackBy(int userId, int itemId, int dir)
        {                           
            return null;
        }

        public List<Item> GetItemByAuctioneer(int auctioneerId)
        {
            return null;
        }

        
    }
}